package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.SystemDictionaryItem;
import cn.wolfcode.crm.mapper.SystemDictionaryItemMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.query.SystemDictionaryItemQueryObject;
import cn.wolfcode.crm.service.ISystemDictionaryItemService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemDictionaryItemServiceImpl implements ISystemDictionaryItemService {

    @Autowired
    private SystemDictionaryItemMapper systemDictionaryItemMapper;

    @Override
    public PageInfo<SystemDictionaryItem> selectByQo(SystemDictionaryItemQueryObject qo) {

        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),"sequence desc");
        List<SystemDictionaryItem> list = systemDictionaryItemMapper.selectAll(qo);
        PageInfo<SystemDictionaryItem> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public void saveOrUpdate(SystemDictionaryItem systemDictionaryItem) {
        if(systemDictionaryItem.getId()==null){
            systemDictionaryItemMapper.insert(systemDictionaryItem);
        }else{
            systemDictionaryItemMapper.updateByPrimaryKey(systemDictionaryItem);
        }
    }


    @Override
    public void deleteBydeptId(Long deptId) {
        systemDictionaryItemMapper.deleteByPrimaryKey(deptId);
    }

    @Override
    public List<SystemDictionaryItem> listByDictionarySn(String sn) {
        List<SystemDictionaryItem> list = systemDictionaryItemMapper.listByDictionarySn(sn);
        return list;
    }
}
